﻿using System;

namespace BLWCMS.Core.Helpers
{
    public class DateHelper
    {
        #region 计算人性化时间
        /// <summary>
        /// 计算人性化时间
        /// </summary>
        /// <param name="DateStart">开始时间</param>
        /// <param name="DateEnd">结束时间</param>
        /// <returns></returns>
        public static string GerPersonalTime(DateTime DateStart, DateTime DateEnd)
        {
            DateTime dateStart = DateStart;
            DateTime dateEnd = DateEnd;

            TimeSpan timeSpan = new TimeSpan(0, 0, 0, Convert.ToInt32(dateEnd.Subtract(dateStart).TotalSeconds));

            int years = timeSpan.Days / 365;
            int months = timeSpan.Days / 30;
            int days = timeSpan.Days;
            int hours = timeSpan.Hours;
            int minutes = timeSpan.Minutes;

            if (years >= 1)
            {
                return years + "年前";
            }
            else
            {
                if (months >= 1)
                {
                    return months + "个月前";
                }
                else
                {
                    if (days >= 1)
                    {
                        return days + "天前";
                    }
                    else
                    {
                        if (hours >= 1)
                        {
                            return hours + "小时前";
                        }
                        else
                        {
                            if (minutes >= 1)
                            {
                                return minutes + "分钟前";
                            }
                            else
                            {
                                return "刚刚";
                            }
                        }
                    }
                }
            }
        } 
        #endregion
    }
}
